#include "EndPit.h"
#include <gl/glut.h>

// End pit diffuse color gray
GLfloat ePit_shininess[] = {0.40, 0.40, 0.40, 1.0 };

//GLfloat material_shininess = { 100 };

EndPit::EndPit(void)
{
	float teamNumSizeFirst = 0.4;
	float teamNumSizeSecond = 0.1;
	Image* image = loadBMP("textures\\rustymetal.bmp");
	pitTexture = loadTexture(image);
	delete image;
}

void EndPit::drawCube(void) {
	// vertices
	GLfloat A[] = { 0.0f, 1.0f, 1.0f }; 
	GLfloat B[] = { 1.0f, 1.0f, 1.0f }; 
	GLfloat C[] = { 1.0f, 1.0f, 0.0f }; 
	GLfloat D[] = { 0.0f, 1.0f, 0.0f }; 
	GLfloat E[] = { 0.0f, 0.0f, 1.0f }; 
	GLfloat F[] = { 1.0f, 0.0f, 1.0f }; 
	GLfloat G[] = { 1.0f, 0.0f, 0.0f }; 
	GLfloat H[] = { 0.0f, 0.0f, 0.0f }; 

	// texture coordinates
	GLfloat bottomLeft[] = {0.0f, 0.0f};
	GLfloat bottomRight[] = {1.0f, 0.0f};
	GLfloat topLeft[] = {0.0f, 1.0f};
	GLfloat topRight[] = {1.0f, 1.0f};

	// top
	glBegin(GL_QUADS);
		glNormal3f( 0.0, 1.0, 0.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(A);
		glTexCoord2fv(bottomRight);
		glVertex3fv(B);
		glTexCoord2fv(topRight);
		glVertex3fv(C);
		glTexCoord2fv(topLeft);
		glVertex3fv(D);
	glEnd();

	// bottom
	glBegin(GL_QUADS);
		glNormal3f( 0.0, -1.0, 0.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(H);
		glTexCoord2fv(bottomRight);
		glVertex3fv(G);
		glTexCoord2fv(topRight);
		glVertex3fv(F);
		glTexCoord2fv(topLeft);
		glVertex3fv(E);
	glEnd();

	// Front
	glBegin(GL_QUADS);
		glNormal3f( 0.0, 0.0, 1.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(E);
		glTexCoord2fv(bottomRight);
		glVertex3fv(F);
		glTexCoord2fv(topRight);
		glVertex3fv(B);
		glTexCoord2fv(topLeft);
		glVertex3fv(A);
	glEnd();

	// back
	glBegin(GL_QUADS);
		glNormal3f( 0.0, 0.0, -1.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(G);
		glTexCoord2fv(bottomRight);
		glVertex3fv(H);
		glTexCoord2fv(topRight);
		glVertex3fv(D);
		glTexCoord2fv(topLeft);
		glVertex3fv(C);
	glEnd();

	// left
	glBegin(GL_QUADS);
		glNormal3f( -1.0, 0.0, 0.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(H);
		glTexCoord2fv(bottomRight);
		glVertex3fv(E);
		glTexCoord2fv(topRight);
		glVertex3fv(A);
		glTexCoord2fv(topLeft);
		glVertex3fv(D);
	glEnd();

	// right
	glBegin(GL_QUADS);
		glNormal3f( 1.0, 0.0, 0.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(F);
		glTexCoord2fv(bottomRight);
		glVertex3fv(G);
		glTexCoord2fv(topRight);
		glVertex3fv(C);
		glTexCoord2fv(topLeft);
		glVertex3fv(B);
	glEnd();
}


EndPit::~EndPit(void)
{
}

void EndPit::display(int up, int left)
{
	glPushMatrix();
		glMaterialfv(GL_FRONT, GL_DIFFUSE, ePit_shininess);	
		glColor3f(1.0, 1.0, 1.0);
		glBindTexture(GL_TEXTURE_2D, pitTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

		// Bottom cube
		glPushMatrix();
			glTranslatef(-0.5, -0.25, -0.5);
			glTranslatef(0.0, -0.25, 0.0);
			glScalef(1.0, 0.5, 1.0);
			//glutSolidCube(1.0);
			drawCube();
		glPopMatrix();

		// Left cube
		glPushMatrix();
			glTranslatef(-0.15, -0.5, -0.5);
			glTranslatef(-0.35, 0.0, 0.0);
			glScalef(0.3, 1.0, 1.0);
			//glutSolidCube(1.0);
			drawCube();
		glPopMatrix();

		// Right cube
		glPushMatrix();
			glTranslatef(-0.15, -0.5, -0.5);
			glTranslatef(0.35, 0.0, 0.0);
			glScalef(0.3, 1.0, 1.0);
			//glutSolidCube(1.0);
			drawCube();
		glPopMatrix();

		// Top front cube
		glPushMatrix();
			glTranslatef(-0.5, -0.5, -0.20);
			glTranslatef(0.0, 0.0, 0.3);
			glScalef(1.0, 1.0, 0.4);
			//glutSolidCube(1.0);
			drawCube();
		glPopMatrix();

		// Produces team number
		//displayNumber(up, left);
	glPopMatrix();
}

void EndPit::displayNumber(int up, int left)
{
	// Produces team number
	glPushMatrix();
		glTranslatef(teamNumSizeFirst/3, 0.025 + teamNumSizeSecond/2, 0.0);
		glPushMatrix();
			glTranslatef(-teamNumSizeFirst/3, 0.0, -teamNumSizeFirst/8);
			glScalef(2*teamNumSizeFirst/3, 0.05, teamNumSizeFirst/4);
			glColor3f(0, 1, 0);
			glutSolidCube(1.0);
		glPopMatrix();
		glPushMatrix();
			glRotatef(-25, 0.0, 1.0, 0.0);
			glTranslatef(-teamNumSizeFirst/8, 0.0, teamNumSizeFirst/2);
			glScalef(teamNumSizeFirst/4, 0.05, teamNumSizeFirst);
			glColor3f(0, 1, 0);
			glutSolidCube(1.0);
		glPopMatrix();
	glPopMatrix();
}